<?php

namespace app\admin\controller\xmwms;

use Exception;
use app\common\controller\Backend;

class WarehousingOrderDetail extends Backend
{
    /**
     * @var \app\admin\model\xmwms\WarehousingOrderDetail
     */
    protected $model = null;

    protected $preExcludeFields = ['id', 'create_time', 'update_time'];

    protected $quickSearchField = ['id'];

    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\admin\model\xmwms\InventoryHistory();
    }

    /**
     * 查看
     */
    public function index()
    {
        $this->request->filter(['strip_tags', 'trim']);
        // 如果是select则转发到select方法,若select未重写,其实还是继续执行index
        if ($this->request->param('select')) {
            $this->select();
        }

        list($where, $alias, $limit) = $this->queryBuilder();
        $res = $this->model
            ->with(['warehouseOrder' => function ($query) {
                $query->field('id,receipt_no,order_sn,supplier_id,admin_id,type,audit_status,remark,create_time,update_time')
                    ->with(['admin'  => function ($queryAdmin) {
                        $queryAdmin->field('id,username');
                    }, 'wmsSupplier' => function ($querySupplier) {
                        $querySupplier->field('id,name,city,address');
                    }
                    ]);
            }, 'product'             => function ($queryProduct) {
                $queryProduct->field('id,product_no,bar_code,name,brand_id,unit_id,spec')
                    ->with(['wmsUnit' => function ($queryUnit) {
                        $queryUnit->field('id,name');
                    }
                    ]);
            }
            ])
            ->alias($alias)
            ->where($where)
            ->order('update_time asc')
            ->paginate($limit);
        $this->success('', [
            'list'   => $res->items(),
            'total'  => $res->total(),
            'remark' => get_route_remark(),
        ]);
    }

}